﻿var doback = {
    success: responseSuccess,
    failure: responseFailure
};
 var responseSuccess = function (res) {
                    try {
                        var str = res.responseText;
                        //var obj = eval(str);
                        if(str=="1"){
                            alert("数据保存成功");
                            //if(action=='insert'){
                                  parent.LoadData();
//                                  parent.closeWin(2);
//                            }else{
//                                parent.ReLoadData();
//                               //parent.fnUpdateRow(instance[0]);
//                            }
                            parent.closeWin();
                        }
                        else
                        {
                            if(str!=""){
                                showMessage();
                                alert(str+"\n"+"数据保存失败!");
                            }
                        }
                    }
                    catch (e) {
                    }
                    finally {
                    }
        };

        var responseFailure = function (error) {
            alert("数据错误：" + error.statusText);
        };

        var fnCustomSave = function () {
    if (typeof (trySave) == "function") {
        var msg = ""; //fnCheckData(instance[0]);
        if (!msg == "") {
            alert(msg);
            return;
        }
        setValue();
        instance[0].IsDefalt = "0";
        instance[0].RoleId = getPar1('RoleId');
        var json = $.toJSON(instance[0]).replace(/'/g, "[B]");
        $("#jsonDataContent").val(json);
        var formObject = document.getElementById('form2');
        YAHOO.util.Connect.setForm(formObject);
        var cObj = YAHOO.util.Connect.asyncRequest('POST', url + "?flag=1&action=" + action + "&entity=" + entity , doback);
    }

}

//获取url里的参数值 name:参数名称
function getPar(source, name) {
    var reg = new RegExp("(^|\\?|&)" + name + "=([^&]*)(\\s|&|$)", "i");
    if (reg.test(source))
        return RegExp.$2;
    return "";
};
function getPar1(name) {
    var _url = "http://" + document.location;
    return getPar(_url, name);
}